/*************************************************
 ** preload为预加载模块，该文件将会在程序启动时加载 **
 *************************************************/

const {logger} = require('ee-core/log');
const TrayAddon = require("../service/os/tray");
const CoreWindow = require('ee-core/electron/window');
const {Menu, MenuItem} = require('electron');

function preload() {
    logger.info('[preload] load 1');
    new TrayAddon().create();
    let applicationMenu = Menu.getApplicationMenu();
    logger.info(applicationMenu.commandsMap['12'].submenu);
    CoreWindow.getMainWindow().removeMenu();
    let menu = new Menu();
    menu.append(new MenuItem({
        label: '菜单',
        submenu: [
            {
                label: '菜单1',
                click: function () {
                    logger.info('菜单1');
                }
            },
            {
                label: '菜单2',
                click: function () {
                    logger.info('菜单2');
                }
            }
        ]
    }))
    menu.on('menu-will-close', function () {

    })
    menu.on('menu-will-show', function () {
        logger.info("show");
    })
    CoreWindow.getMainWindow().setMenu(menu);
    menu.popup()


    for (const type of ["chrome", "node", "electron"]) {
        logger.info(`${type}-version${process.versions[type]}`)
    }

}

/**
 * 预加载模块入口
 */
module.exports = {
    preload
}